
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
    <head>
        <title>Android user mapping</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    </head>
    <style type="text/css">
    form
    {
        text-align:center;
    }
    </style>
    <body>

<?php
  include_once('connect.php');
  include_once('updateGlobeDB.php');
  include_once('updateGlobemagDB.php');
  include_once('fileWriter.php');
  //include_once('updateCountryDB.php');
  
  //login to the database
  $db = connect();
  
  //collect data from the url
  $userID = $_GET['userID'];
  $lat = $_GET['lat'];
  $lon = $_GET['lon'];
  //$country = $_GET['country'];
  
  //formating $lat and $lon with wanted precision
  $PRECISION = 5;
  
  // -180 <= longitude <= 180
  for ($i = -180; $i <= 180; $i += $PRECISION) {
      if ($lon > $i)
          $lon_cell = $i;
  }
  
  // -90 <= latitude <= 90
  for ($i = -90; $i <= 90; $i += $PRECISION) {
      if ($lat > $i)
          $lat_cell = $i;
  }
  
  //insert or update of 'globe' table
  $req = $db->prepare('SELECT * FROM globe WHERE userID = ?');
  $req->execute(array($userID));
  $donnee = $req->fetch();
  
  if ($donnee == null)
	updateGlobeDB($db, $userID, $lat_cell, $lon_cell, false); //updateGlobeDB($db, $userID, $lat_cell, $lon_cell, $country, false);     
  else
	updateGlobeDB($db, $userID, $lat_cell, $lon_cell, false);
     //updateGlobeDB($db, $userID, $lat_cell, $lon_cell, $country, true);
      updateGlobeDB($db, $userID, $lat_cell, $lon_cell, $country, true);  
  //empty 'globemag' table
  $req = $db->prepare('DELETE FROM globemag');
  $req->execute(array());
  $req = $db->prepare('ALTER TABLE globemag AUTO_INCREMENT=0');
  $req->execute(array());
  
  //'globemag' table update
  updateGlobemagDB($db);
  
  //'country' table update
  //updateCountryDB($db);
  
  //writing of the .json file
  fileWriter($db);
?>
</body>
</html>
